package edu.sfsu.powerrangers.jeopardy.gamestate;

import java.io.Serializable;
import java.util.Collection;
import java.util.Vector;

public class GameState implements Cloneable, Serializable {
	private static final long serialVersionUID = 1L;

	private Host host = null;
	private Vector<Contestant> contestants = new Vector<Contestant>();
	private Game game = null;
	private Round currentRound = null;
	private FinalRound currentFinalRound = null;
	private Contestant currentClueSelector = null;
	private Contestant currentResponder = null;
	private Category currentCategory = null;
	private Clue currentClue = null;
	
	public GameState clone() {
		GameState gs = new GameState();
		if (this.host != null) gs.host = this.host.clone();
		for (Contestant c : this.contestants) gs.contestants.add(c.clone());
		if (this.game != null) gs.game = this.game.clone();
		return gs;
	}
	
	public Host getHost() {
		return host;
	}
	
	public void setHost(Host host) {
		this.host = host;
	}
	
	public Contestant[] getContestants() {
		return contestants.toArray(new Contestant[0]);
	}
	
	public String[] getContestantNames() {
		Vector<String> v = new Vector<String>();
		for (Contestant c : contestants) v.add(c.getName());
		return v.toArray(new String[0]);
	}
	
	public int getContestantCount() {
		return contestants.size();
	}
	
	public Contestant getContestant(int i) {
		return contestants.get(i);
	}
	
	public String getContestantName(int i) {
		return contestants.get(i).getName();
	}
	
	public void addContestant(Contestant c) {
		contestants.add(c);
	}
	
	public void removeContestant(Contestant c) {
		contestants.remove(c);
		if (currentClueSelector != null && currentClueSelector.equals(c)) {
			currentClueSelector = null;
		}
		if (currentResponder != null && currentResponder.equals(c)) {
			currentResponder = null;
		}
	}
	
	public void removeAllContestants() {
		contestants.clear();
		currentClueSelector = null;
		currentResponder = null;
	}
	
	public void setContestants(Collection<? extends Contestant> c) {
		contestants.clear();
		contestants.addAll(c);
		currentClueSelector = null;
		currentResponder = null;
	}
	
	public Game getGame() {
		return game;
	}
	
	public void setGame(Game game) {
		this.game = game;
		this.currentRound = null;
		this.currentFinalRound = null;
	}
	
	public Round getCurrentRound() {
		return currentRound;
	}
	
	public void setCurrentRound(Round round) {
		currentRound = round;
		currentFinalRound = null;
	}
	
	public FinalRound getCurrentFinalRound() {
		return currentFinalRound;
	}
	
	public void setCurrentFinalRound(FinalRound round) {
		currentRound = null;
		currentFinalRound = round;
	}
	
	public Contestant getCurrentClueSelector() {
		return currentClueSelector;
	}
	
	public void setCurrentClueSelector(Contestant selector) {
		currentClueSelector = selector;
	}
	
	public Contestant getCurrentResponder() {
		return currentResponder;
	}
	
	public void setCurrentResponder(Contestant responder) {
		currentResponder = responder;
	}
	
	public Category getCurrentCategory() {
		return currentCategory;
	}
	
	public Clue getCurrentClue() {
		return currentClue;
	}
	
	public void setCurrentClue(Category cat, Clue c) {
		currentCategory = cat;
		currentClue = c;
	}
}
